import {connect} from 'react-redux'
import Cart from '../../components/merchantInfo/cart'
import {Gocart} from '../../action/index'

const mapStateToProps=state=>{
    let price=0;
    state.reducer.products.forEach(item => {
            item.foods.forEach(val=>{
                if(val.totalPrice != 0) {
                    price+= val.totalPrice
                }
            })
    });
    return{
        totalPrice:price,
        pro:state.reducer.products
    }
}

const mapDispatchTopProps=dispatch=>{
    return{
      GoCart(pro){
          Gocart(pro,dispatch)
      }
    }
}

export default connect(mapStateToProps,mapDispatchTopProps)(Cart)